public class Animals {
    String name;
    int age;
    float weight;
    public void eat(){
        System.out.println(name + "正在吃饭");
    }
    public void sleep()
    {
        System.out.println(name + "正在睡觉");
        System.out.println(name + "zhnegxa");
        System.out.println(name + "isjivs");
        System.out.println(name + "kolsvoliks");
    }

    public Animals(int age) {
        this.age = age;
    }
    int sizeof = 0;

    public void getLeafNodeCount(TreeNode root) {
        if(root == null) {
            return ;
        }
        if(root.left == null && root.right == null) {
            sizeof ++;
        }
        getLeafNodeCount(root.left);
        getLeafNodeCount(root.right);
    }

    public int getLeafNodeCount2(TreeNode root) {
        if(root == null) {
            return 0;
        }
        if(root.left == null && root.right == null) {
            return 1;
        }
        return   getLeafNodeCount2(root.left) + getLeafNodeCount2(root.right);

    }
    public void getLeafNodeCount(TreeNode root,int k) {
        if(root == null) {
            return ;
        }
     if(k == 1) {
         sizeof ++;
     }
        getLeafNodeCount(root.left,k--);
        getLeafNodeCount(root.right,k--);
    }
    public TreeNode findVal(TreeNode root,char val) {
        if(root == null) {
            return null;
        }
        if(root.val == val) {
            return root;
        }
        TreeNode ret = findVal(root.left,val);
        if(ret != null){
            return ret;
        }
        TreeNode rgb= findVal(root.right,val);
        if(rgb != null){
            return rgb;
        }
    }
    class Solution {
        public boolean isSymmetric(TreeNode root) {
            if(root == null) {
                return true;
            }
            return isSameTree(root.left,root.right);
        }
        public boolean isSameTree(TreeNode p, TreeNode q) {
//1.先判断结构是否是一样的
            if(p != null && q == null || p == null && q != null) {
                return false;
            }
//上述if语句 如果没有执行，意味着两个引用 同时为空 或者同时不为空
            if(p == null && q == null) {
                return true;
            }
//都不为空 判断值是否一样
            if(p.val != q.val) {
                return false;
            }
//都不为空且值一样
            return isSameTree(p.left,q.right) &&  isSameTree(p.right,q.left);
        }
    }
    public class BinaryTree {

        static class TreeNode {
            public char val;
            public TreeNode left;//左孩子的引用
            public TreeNode right;//右孩子的引用

            public TreeNode(char val) {
                this.val = val;
            }
        }


        /**
         * 创建一棵二叉树 返回这棵树的根节点
         *
         * @return
         */

        public TreeNode createTree() {
            TreeNode as =
        }

        // 前序遍历
        public void preOrder(TreeNode root) {
            if(root == null) {
                return;
            }
            System.out.println(root.val);
            preOrder(root.left);
            preOrder(root.right);
        }

        // 中序遍历
        void inOrder(TreeNode root) {
            if(root == null) {
                return;
            }
            preOrder(root.left);
            System.out.println(root.val);
            preOrder(root.right);
        }

        // 后序遍历
        void postOrder(TreeNode root) {
            if(root == null) {
                return;
            }
            preOrder(root.left);
            preOrder(root.right);
            System.out.println(root.val);
        }

        public static int nodeSize;

        /**
         * 获取树中节点的个数：遍历思路
         */
        void size(TreeNode root) {
            if(root == null) {
                return;
            }
            nodeSize++;
            preOrder(root.left);
            preOrder(root.right);
        }

        /**
         * 获取节点的个数：子问题的思路
         *
         * @param root
         * @return
         */
        int size2(TreeNode root) {
            if(root == null) {
                return 0;
            }
           int leftt = preOrder(root.left);
            int rightt = preOrder(root.right);
            return leftt + rightt + 1;
        }


        /*
         获取叶子节点的个数：遍历思路
         */
        public static int leafSize = 0;

        void getLeafNodeCount1(TreeNode root) {
            if(root == null) {
                return;
            }
            if(root.left == null && root.right == null) {
                leafSize++;
            }
            getLeafNodeCount1(root.left);
            getLeafNodeCount1(root.right);
        }

        /*
         获取叶子节点的个数：子问题
         */
        int getLeafNodeCount2(TreeNode root) {
            if(root == null) {
                return 0;
            }
            if(root.left == null && root.right == null) {
               return 1;
            }
            int left = getLeafNodeCount1(root.left);
            int right = getLeafNodeCount1(root.right);
            return left + right;
        }

        /*
        获取第K层节点的个数
         */
        int getKLevelNodeCount(TreeNode root, int k) {
            int size = 0;
            if(k == 1) {
                size++;
            }
            getKLevelNodeCount(root.left,--k);
            getKLevelNodeCount(root.right,--k);
            return size;
        }

        /*
         获取二叉树的高度
         时间复杂度：O(N)
         */
        int getHeight(TreeNode root) {
            if(root == null) {
                return 0;
            }
            int left = getHeight(root.left);
            int right = getHeight(root.right);
            return Math.max(left,right) + 1;
        }


        // 检测值为value的元素是否存在
        TreeNode find(TreeNode root, char val) {
            if(root == null) {
                return null;
            }
            if(root.val == val) {
                return root;
            }
            find(root.left,val);
            find(root.right,val);
            return null;
        }

        //层序遍历
        void levelOrder(TreeNode root) {

        }


        // 判断一棵树是不是完全二叉树
        boolean isCompleteTree(TreeNode root) {
            if(root==null) return false;
            Queue<BTNode> queue=new Linklisted<>();
            queue.offer(root);
            while(!queue.isEmpty())
            {
                BTNode cur=queue.poll();
                if(cur==null)
                {
                    break;
                }else{
                    if(cur.left!=null) queue.offer(cur.left);
                    if(cur.right!=null) queue.offer(cur.right);
                }
            }
            //判断队列中剩余的元素是否为空
            while(!queue.isEmpty())
            {
                BTNode cur=queue.poll();
                if(cur!=null)  return false;
            }
            return true;
        }
    }
    public boolean isCompleteTree(TreeNode root) {
        if (root == null) {
            return fslse;
        }
        Queue<TreeNode> queue = new LinkedList<>();
        queue.offer(root);
        while (!queue.isEmpty()) {
            TreeNode cur = queue.poll();
            if (cur != null) {
                queue.offer(cur.left);
                queue.offer(cur.right);
            } else {
                break;
            }
        }
        while (!queue.isEmpty()) {
            TreeNode cur = queue.peek();
            if (cur == null) {
                return false;
            }
            queue.poll();
        }
        return true;
        public class Solution {
            /**
             * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
             * @param pushV int整型一维数组
             * @param popV  int整型一维数组
             * @return bool布尔型
             */
            public boolean IsPopOrder(int[] pushV, int[] popV) {
                // write code here
                Stack<Integer> stack = new Stack<Integer>();
                int n = pushV.length;
                int j = 0;
                int i = 0;
                for (i = 0; i < n; i++) {
                    while (j < n && (stack.isEmpty() || stack.peek() != popV[i])) {
                        stack.push(pushV[j]);
                        j++;
                    }
                    if (stack.peek() == popV[i]) {
                        stack.pop();
                    } else {
                        return false;
                    }
                }
                return true;
            }
        }
        public static void insetSort ( int[] array){
            for (int i = 1; i < array.length; i++) {
                int j = i - 1;
                for (; j >= 0; j--) {


                }

            }

        }
    }
    class Solution {
        public List<Integer> postorderTraversal(TreeNode root) {
            List<Integer> res = new ArrayList<Integer>();
            if(root == null) {
                return res;
            }
            TreeNode ret = root;
            Deque<TreeNode> stack = new LinkedList<TreeNode>();
            TreeNode prev = null;
            while(root != null || !stack.isEmpty()) {
                while(root != null) {
                    stack.push(root);
                    root = root.left;
                }
                root = stack.pop();
                if(root.right == null || root.right == prev) {
                    res.add(root.val);
                    prev = root;
                    root = null;
                } else {
                    stack.push(root);
                    root = root.right;
                }
            }
            return res;
        }
    }
    public static void stal (int[] array) {
        int left = 0;
        int right = array.length - 1;
        while(left < right) {
            int a = 10;
        }
    }
    public class BinarySearchTree {

        static class TreeNode {
            public int val;
            public TreeNode left;
            public TreeNode right;

            public TreeNode(int val) {
                this.val = val;
            }
        }

        public TreeNode root ;

        public void insert(int key) {

        }

        public TreeNode search(TreeNode root,int val) {
            if (root == null) {
                return root;
            }
            TreeNode cur = root;
            while(cur != null) {
                if (cur.val == val) {
                    return cur;
                } else if (cur.val > val) {
                    cur = cur.left;
                } else {
                    cur = cur.right;
                }
            }
            return null;
        }
        else {
            TreeNode t=cur;
            TreeNode tp=null;
            while(t.left!=null){
                tp=t;
                t=t.left;
            }
            cur.val=t.val;
            tp.left=t.right;
        }
        else {
            TreeNode t=cur;
            TreeNode tp=null;
            while(t.left!=null){
                tp=t;
                t=t.left;
            }
            cur.val=t.val;
            tp.left=t.right;
        }
        while (cur != null) {
            if(cur.val > key) {
                parent = cur;
                cur = cur.left;
            } else if(cur.val == key) {

                return;
            }else {
                parent = cur;
                cur = cur.right;
            }
        }else {
            TreeNode tp = null;
            TreeNode t = cur.right;
            while(t.left != null) {
                tp = t;
                t = t.left;
            }
            cur.val = t.val;
            if(tp.left == t){
                tp.left = t.right;
            } else {
                tp.right = t.right;
            }

        }else {
            TreeNode tp = null;
            TreeNode t = cur.right;
            while(t.left != null) {
                tp = t;
                t = t.left;
            }
            cur.val = t.val;
            if(tp.left == t){
                tp.left = t.right;
            } else {
                tp.right = t.right;
            }
            else {
                TreeNode tp = null;
                TreeNode t = cur.right;
                while(t.left != null) {
                    tp = t;
                    t = t.left;
                }
                cur.val = t.val;
                if(tp.left == t){
                    tp.left = t.right;
                } else {
                    tp.right = t.right;
                }
                 else {
                    TreeNode tp = null;
                    TreeNode t = cur.right;
                    while(t.left != null) {
                        tp = t;
                        t = t.left;
                    }
                    cur.val = t.val;
                    if(tp.left == t){
                        tp.left = t.right;
                    } else {
                        tp.right = t.right;
                    }
                    else {
                        TreeNode tp = null;
                        TreeNode t = cur.right;
                        while(t.left != null) {
                            tp = t;
                            t = t.left;
                        }
                        cur.val = t.val;
                        if(tp.left == t){
                            tp.left = t.right;
                        } else {
                            tp.right = t.right;
                        }
                         else {
                            TreeNode tp = null;
                            TreeNode t = cur.right;
                            while(t.left != null) {
                                tp = t;
                                t = t.left;
                            }
                            cur.val = t.val;
                            if(tp.left == t){
                                tp.left = t.right;
                            } else {
                                tp.right = t.right;
                            }
                            else {
                                TreeNode tp = null;
                                TreeNode t = cur.right;
                                while(t.left != null) {
                                    tp = t;
                                    t = t.left;
                                }
                                cur.val = t.val;
                                if(tp.left == t){
                                    tp.left = t.right;
                                } else {
                                    tp.right = t.right;
                                }
                                else {
                                    TreeNode tp = null;
                                    TreeNode t = cur.right;
                                    while(t.left != null) {
                                        tp = t;
                                        t = t.left;
                                    }
                                    cur.val = t.val;
                                    if(tp.left == t){
                                        tp.left = t.right;
                                    } else {
                                        tp.right = t.right;
                                    }
                                     else {
                                        TreeNode tp = null;
                                        TreeNode t = cur.right;
                                        while(t.left != null) {
                                            tp = t;
                                            t = t.left;
                                        }
                                        cur.val = t.val;
                                        if(tp.left == t){
                                            tp.left = t.right;
                                        } else {
                                            tp.right = t.right;
                                        }
                                        else {
                                            TreeNode tp = null;
                                            TreeNode t = cur.right;
                                            while(t.left != null) {
                                                tp = t;
                                                t = t.left;
                                            }
                                            cur.val = t.val;
                                            if(tp.left == t){
                                                tp.left = t.right;
                                            } else {
                                                tp.right = t.right;
                                            }
                                            else {
                                                TreeNode tp = null;
                                                TreeNode t = cur.right;
                                                while(t.left != null) {
                                                    tp = t;
                                                    t = t.left;
                                                }
                                                cur.val = t.val;
                                                if(tp.left == t){
                                                    tp.left = t.right;
                                                } else {
                                                    tp.right = t.right;
                                                }
                                                else {
                                                    TreeNode tp = null;
                                                    TreeNode t = cur.right;
                                                    while(t.left != null) {
                                                        tp = t;
                                                        t = t.left;
                                                    }
                                                    cur.val = t.val;
                                                    if(tp.left == t){
                                                        tp.left = t.right;
                                                    } else {
                                                        tp.right = t.right;
                                                    }
                                                     else {
                                                        TreeNode tp = null;
                                                        TreeNode t = cur.right;
                                                        while(t.left != null) {
                                                            tp = t;
                                                            t = t.left;
                                                        }
                                                        cur.val = t.val;
                                                        if(tp.left == t){
                                                            tp.left = t.right;
                                                        } else {
                                                            tp.right = t.right;
                                                        }
                                                        else {
                                                            TreeNode tp = null;
                                                            TreeNode t = cur.right;
                                                            while(t.left != null) {
                                                                tp = t;
                                                                t = t.left;
                                                            }
                                                            cur.val = t.val;
                                                            if(tp.left == t){
                                                                tp.left = t.right;
                                                            } else {
                                                                tp.right = t.right;
                                                            }
                                                            else {
                                                                TreeNode tp = null;
                                                                TreeNode t = cur.right;
                                                                while(t.left != null) {
                                                                    tp = t;
                                                                    t = t.left;
                                                                }
                                                                cur.val = t.val;
                                                                if(tp.left == t){
                                                                    tp.left = t.right;
                                                                } else {
                                                                    tp.right = t.right;
                                                                }
                                                                else {
                                                                    TreeNode tp = null;
                                                                    TreeNode t = cur.right;
                                                                    while(t.left != null) {
                                                                        tp = t;
                                                                        t = t.left;
                                                                    }
                                                                    cur.val = t.val;
                                                                    if(tp.left == t){
                                                                        tp.left = t.right;
                                                                    } else {
                                                                        tp.right = t.right;
                                                                    }
                                                                    else {
                                                                        TreeNode tp = null;
                                                                        TreeNode t = cur.right;
                                                                        while(t.left != null) {
                                                                            tp = t;
                                                                            t = t.left;
                                                                        }
                                                                        cur.val = t.val;
                                                                        if(tp.left == t){
                                                                            tp.left = t.right;
                                                                        } else {
                                                                            tp.right = t.right;
                                                                        }
                                                                         else {
                                                                            TreeNode tp = null;
                                                                            TreeNode t = cur.right;
                                                                            while(t.left != null) {
                                                                                tp = t;
                                                                                t = t.left;
                                                                            }
                                                                            cur.val = t.val;
                                                                            if(tp.left == t){
                                                                                tp.left = t.right;
                                                                            } else {
                                                                                tp.right = t.right;
                                                                            }
                                                                            else {
                                                                                TreeNode tp = null;
                                                                                TreeNode t = cur.right;
                                                                                while(t.left != null) {
                                                                                    tp = t;
                                                                                    t = t.left;
                                                                                }
                                                                                cur.val = t.val;
                                                                                if(tp.left == t){
                                                                                    tp.left = t.right;
                                                                                } else {
                                                                                    tp.right = t.right;
                                                                                }
                                                                                else {
                                                                                    TreeNode tp = null;
                                                                                    TreeNode t = cur.right;
                                                                                    while(t.left != null) {
                                                                                        tp = t;
                                                                                        t = t.left;
                                                                                    }
                                                                                    cur.val = t.val;
                                                                                    if(tp.left == t){
                                                                                        tp.left = t.right;
                                                                                    } else {
                                                                                        tp.right = t.right;
                                                                                    }
                                                                                    else {
                                                                                        TreeNode tp = null;
                                                                                        TreeNode t = cur.right;
                                                                                        while(t.left != null) {
                                                                                            tp = t;
                                                                                            t = t.left;
                                                                                        }
                                                                                        cur.val = t.val;
                                                                                        if(tp.left == t){
                                                                                            tp.left = t.right;
                                                                                        } else {
                                                                                            tp.right = t.right;
                                                                                        }
                                                                                        else {
                                                                                            TreeNode tp = null;
                                                                                            TreeNode t = cur.right;
                                                                                            while(t.left != null) {
                                                                                                tp = t;
                                                                                                t = t.left;
                                                                                            }
                                                                                            cur.val = t.val;
                                                                                            if(tp.left == t){
                                                                                                tp.left = t.right;
                                                                                            } else {
                                                                                                tp.right = t.right;
                                                                                            }
                                                                                            else {
                                                                                                TreeNode tp = null;
                                                                                                TreeNode t = cur.right;
                                                                                                while(t.left != null) {
                                                                                                    tp = t;
                                                                                                    t = t.left;
                                                                                                }
                                                                                                cur.val = t.val;
                                                                                                if(tp.left == t){
                                                                                                    tp.left = t.right;
                                                                                                } else {
                                                                                                    tp.right = t.right;
                                                                                                }
                                                                                                else {
                                                                                                    TreeNode tp = null;
                                                                                                    TreeNode t = cur.right;
                                                                                                    while(t.left != null) {
                                                                                                        tp = t;
                                                                                                        t = t.left;
                                                                                                    }
                                                                                                    cur.val = t.val;
                                                                                                    if(tp.left == t){
                                                                                                        tp.left = t.right;
                                                                                                    } else {
                                                                                                        tp.right = t.right;
                                                                                                    }
                                                                                                    else {
                                                                                                        TreeNode tp = null;
                                                                                                        TreeNode t = cur.right;
                                                                                                        while(t.left != null) {
                                                                                                            tp = t;
                                                                                                            t = t.left;
                                                                                                        }
                                                                                                        cur.val = t.val;
                                                                                                        if(tp.left == t){
                                                                                                            tp.left = t.right;
                                                                                                        } else {
                                                                                                            tp.right = t.right;
                                                                                                        }
                                                                                                        else {
                                                                                                            TreeNode tp = null;
                                                                                                            TreeNode t = cur.right;
                                                                                                            while(t.left != null) {
                                                                                                                tp = t;
                                                                                                                t = t.left;
                                                                                                            }
                                                                                                            cur.val = t.val;
                                                                                                            if(tp.left == t){
                                                                                                                tp.left = t.right;
                                                                                                            } else {
                                                                                                                tp.right = t.right;
                                                                                                            }
                                                                                                             else {
                                                                                                                TreeNode tp = null;
                                                                                                                TreeNode t = cur.right;
                                                                                                                while(t.left != null) {
                                                                                                                    tp = t;
                                                                                                                    t = t.left;
                                                                                                                }
                                                                                                                cur.val = t.val;
                                                                                                                if(tp.left == t){
                                                                                                                    tp.left = t.right;
                                                                                                                } else {
                                                                                                                    tp.right = t.right;
                                                                                                                }
                                                                                                                 else {
                                                                                                                    TreeNode tp = null;
                                                                                                                    TreeNode t = cur.right;
                                                                                                                    while(t.left != null) {
                                                                                                                        tp = t;
                                                                                                                        t = t.left;
                                                                                                                    }
                                                                                                                    cur.val = t.val;
                                                                                                                    if(tp.left == t){
                                                                                                                        tp.left = t.right;
                                                                                                                    } else {
                                                                                                                        tp.right = t.right;
                                                                                                                    }














































